package com.sumainfor.pc.market.controller;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.market.service.HousingPatrolService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 * 管家巡房
 * @Auther: zhlu
 * @Date: 2019/3/5 21:24
 * @Description:
 */
@RestController
@RequestMapping("/patrol")
public class HousingPatrolController {

    Logger log= LoggerFactory.getLogger(HousingPatrolController.class);

    @Autowired
    HousingPatrolService HousingPatrolService;

    /**
     * 功能描述: 
     * 获取管家巡房列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/5 21:27
     */
    @ResponseBody
    @RequestMapping(value = "/getHousingPatrolList",method = RequestMethod.POST)
    public JsonResult getHousingPatrolList(@RequestBody Map<String,Object>params,Pager pager){
        JsonResult result=new JsonResult();
        params.put("delfg",0);
        //状态 1草稿 2.待审核 3已审核（待装修） 4.装修中 5装修完成 6.验房中 7验房通过
        params.put("State",7);
        pager.setPageno((Integer)params.get("pageno"));
        pager.setPagesize((Integer)params.get("pagesize"));
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=HousingPatrolService.getHousingPatrolListCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> getHousingPatrolList=HousingPatrolService.getHousingPatrolList(params);
        result=pageUtils.getJsonResult(getHousingPatrolList, params, cout);
        return result;
    }

    /**
     * 功能描述:
     * 获取本月巡房问题房源
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/6 11:41
     */
    @GetMapping("/getHousingPatrolData")
    public JsonResult getHousingPatrolData(){
        JsonResult result=new JsonResult();
        Map<String,Object>params=new HashMap<String,Object>();
        List<String> PatStatusList = new ArrayList<String>();
        PatStatusList.add("1");
        params.put("delfg",0);
        //状态 1草稿 2.待审核 3已审核（待装修） 4.装修中 5装修完成 6.验房中 7验房通过
        params.put("State",7);
        params.put("PatStatusList",PatStatusList);

        Map<String,Object> getHousingPatrolData=HousingPatrolService.getHousingPatrolData(params);
        result.put(getHousingPatrolData);
        return result;
    }

    /**
     * 功能描述: 
     * 根据房源编号获取巡房资料
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/8 14:15
     */
    @GetMapping("/getPatrolHousginMap")
    public JsonResult getPatrolHousginMap(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"HouId"})){
            result.putFailed("HouId不能为空！");
            return  result;
        }
        params.put("delfg",0);
        //合同状态电子合同签署状态
        //1,签署中
        //2.已完成: 所有签署人完成签署
        //3 已撤销: 发起方撤销签署任务
        //4 已终止: 至少一个签署人拒签或通过重试
        //不可恢复的签署失败
        //5 已过期: 超时未签署
        params.put("FlowStatus",2);
        result.put(HousingPatrolService.getPatrolHousginMap(params));
        return result;
    }

    /**
     * 功能描述: 
     * 管家新增巡房记录
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/8 16:17
     */
    @ResponseBody
    @RequestMapping(value = "/AddPatrol",method = RequestMethod.POST)
    public JsonResult AddPatrol(@RequestBody Map<String,Object> params)throws Exception{
        JsonResult result=new JsonResult();
        log.info("params---"+params);
        if(HousingPatrolService.AddPatrol(params)){
            result.putSuccess("管家巡房成功！");
        }else{
            result.putFailed("服务器繁忙,请稍后重试！");
        }
        return result;
    }

    /**
     * 功能描述: 
     * 根据管家巡房主编号获取巡房资料
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/9 14:23
     */
    @GetMapping("/getPatrol")
    public JsonResult getPatrol(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"PatId"})){
            result.putFailed("PatId不能为空！");
            return  result;
        }
        result.put(HousingPatrolService.getPatrol(params));
        return result;
    }

    /**
     * 功能描述: 
     * 根据管家巡房主编号和租客违规编号修改租客违规和保洁违规
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/9 18:02
     */
    @ResponseBody
    @RequestMapping(value = "/UpdatePatrol",method = RequestMethod.POST)
    public JsonResult UpdatePatrol(@RequestBody Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(HousingPatrolService.UpdatePatrol(params)){
            result.putSuccess("巡房资料更新成功！");
        }else{
            result.putFailed("服务器繁忙,请稍后重试！");
        }
        return result;
    }

    /**
     * 功能描述: 
     * 根据房源主编号获取当前房源历史租客违规列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/5/23 17:33
     */
    @ResponseBody
    @GetMapping("/getPatrolHousingViolationList")
    public JsonResult getPatrolHousingViolationList(@RequestParam Map<String,Object>params,Pager pager){
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=HousingPatrolService.getPatrolHousingViolationCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> getPatrolHousingViolationList=HousingPatrolService.getPatrolHousingViolationList(params);
        result=pageUtils.getJsonResult(getPatrolHousingViolationList, params, cout);
        return result;
    }

    /**
     * 功能描述:
     * 根据房源主编号获取当前房源历史保洁违规列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/5/23 17:33
     */
    @ResponseBody
    @GetMapping("/getPatrolHousingCleaningList")
    public JsonResult getPatrolHousingCleaningList(@RequestParam Map<String,Object>params,Pager pager){
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=HousingPatrolService.getPatrolHousingCleaningCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> getPatrolHousingViolationList=HousingPatrolService.getPatrolHousingCleaningList(params);
        result=pageUtils.getJsonResult(getPatrolHousingViolationList, params, cout);
        return result;
    }

    /**
     * 功能描述:
     * 历史巡房保洁，根据巡房主编号修改保洁状态
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/9 18:02
     */
    @ResponseBody
    @RequestMapping(value = "/UpdateCleaning",method = RequestMethod.POST)
    public JsonResult UpdateCleaning(@RequestBody Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(HousingPatrolService.UpdateCleaning(params)){
            result.putSuccess("巡房保洁资料更新成功！");
        }else{
            result.putFailed("服务器繁忙,请稍后重试！");
        }
        return result;
    }

    /**
     * 功能描述:
     * 根据巡房记录编号获取租客违规列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/5/23 17:33
     */
    @ResponseBody
    @GetMapping("/getPatrolHousingViolationInfoList")
    public JsonResult getPatrolHousingViolationInfoList(@RequestParam Map<String,Object>params,Pager pager){
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=HousingPatrolService.getPatrolHousingViolationInfoCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> getPatrolHousingViolationInfoList=HousingPatrolService.getPatrolHousingViolationInfoList(params);
        result=pageUtils.getJsonResult(getPatrolHousingViolationInfoList, params, cout);
        return result;
    }

    /**
     * 功能描述:
     * 根据违规记录编号修改某一个租客违规
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/9 18:02
     */
    @ResponseBody
    @RequestMapping(value = "/UpdateViolation",method = RequestMethod.POST)
    public JsonResult UpdateViolation(@RequestBody Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(HousingPatrolService.UpdateViolation(params)){
            result.putSuccess("巡房租客违规资料更新成功！");
        }else{
            result.putFailed("服务器繁忙,请稍后重试！");
        }
        return result;
    }
}
